package com.suning.sawp.in.controller;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.suning.sawp.constants.ErrorCodeConstants;
import com.suning.sawp.dto.common.QueryResult;
import com.suning.sawp.dto.common.ReturnMsg;
import com.suning.sawp.intf.assistant.ClientVersionManageService;
import com.suning.sawp.po.assistant.ClientVersionManage;

/**
 * 
 * 终端管理-IM关闭临时迁到这<br> 
 * 〈功能详细描述〉
 *
 * @author 12061818
 * @see [相关类/方法]（可选）
 * @since [产品/模块版本] （可选）
 */
@Controller
@RequestMapping("/adminPage/clientVersion")
public class ClinetVersionController extends DjBaseController {
    
    private static final Logger LOGGER = LoggerFactory.getLogger(ClinetVersionController.class);
    
    @Resource
    ClientVersionManageService clientVersionManageService;
    
    @RequestMapping("/query.do")
    public MyGsonView query(Long id, int pageNo, int pageSize) {
        ReturnMsg<QueryResult<ClientVersionManage>> returnMsg = new ReturnMsg<QueryResult<ClientVersionManage>>();
        LOGGER.info("clinetVersion/query.do, id:{}, pageNo:{}, pageSize:{}", new Object[]{id, pageNo, pageSize});
        try {
            QueryResult<ClientVersionManage> queryResult = 
                    clientVersionManageService.query(id, pageNo, pageSize);
            returnMsg.setData(queryResult);
        } catch (Exception e) {
            returnMsg.setError(ErrorCodeConstants.ERR_0002);
            LOGGER.error("clinetVersion/query.do fail.", e);
        }
        
        return setGsonView(returnMsg);
    }
    
    @RequestMapping("/edit.do")
    @ResponseBody
    public ReturnMsg<String> edit(ClientVersionManage versionManage) {
        ReturnMsg<String> returnMsg = new ReturnMsg<String>();
        LOGGER.info("clinetVersion/edit.do, versionManage:{}", versionManage);
        try {
            clientVersionManageService.editClientVersionManage(versionManage);
        } catch (Exception e) {
            returnMsg.setError(ErrorCodeConstants.ERR_0002);
            LOGGER.error("clinetVersion/edit.do fail.", e);
        }
        
        return returnMsg;
    }
    
    @RequestMapping("/delete.do")
    @ResponseBody
    public ReturnMsg<String> delete(Long id) {
        ReturnMsg<String> returnMsg = new ReturnMsg<String>();
        LOGGER.info("clinetVersion/delete.do, id:{}", id);
        try {
            clientVersionManageService.deleteClientVersionManage(id);
        } catch (Exception e) {
            returnMsg.setError(ErrorCodeConstants.ERR_0002);
            LOGGER.error("clinetVersion/delete.do fail.", e);
        }
        
        return returnMsg;
    }
}
